import java.util.ArrayList;
import java.util.List;

public class Solution1592 {
    public String reorderSpaces(String text) {
        String[] strings=text.split(" ");
        List<String> list=new ArrayList<>();
        for (String string : strings) {
            if (string.length()>0){
                list.add(string);
            }
        }
        int a=0;
        for (char c : text.toCharArray()) {
            if (c==' '){
                a++;
            }
        }
        int n=list.size()!=1?a/(list.size()-1):0;
        int m=a-(list.size()-1)*n;
        StringBuilder stringBuilder=new StringBuilder();
        for (int i=0;i<list.size();i++){
            stringBuilder.append(list.get(i));
            if (i!=list.size()-1){
                for (int j=0;j<n;j++){
                    stringBuilder.append(" ");
                }
            }
        }
        for (int i=0;i<m;i++){
            stringBuilder.append(" ");
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1592().reorderSpaces("  this   is  a sentence "));
    }
}
